$(document).ready (function (){
    
    // init components
    
    var auth_dialog = {
        autoOpen: false,
        modal: true,
        title: lang.ru.auth_form_title,
        close: function ()
        {
            var alert_dialog = {
                closeOnEscape:false,
                title: lang.ru.alert_title,
                autoOpen: false,
                modal: true,
                buttons:
                {
                    "Ok": function()
                    {
                        $('#auth_form').dialog('open');
                    }
                },
                close: function ()
                {
                    $('#auth_form').dialog('open');
                }
            }
            $('#alert').html ('<p>'+lang.ru.not_auth_form_close+'</p>');
            $('#alert').dialog ( alert_dialog );
            $('#alert').dialog('open');
        }
    }
    
    $('#auth_form').dialog ( auth_dialog );
    
    var auth_form_ajax_submit = {}
    
    $ ('#auth_form_form').ajaxSubmit ( auth_form_ajax_submit );
    
    // app start
    
    $.getJSON('http://webchat.local/server.php?callback=?', {action: 'ping'}, function (json){
        switch ( json.code )
        {
            case '401':
                // пользователь не авторизован
                $('#auth_form').dialog('open');
                break;
        }
        
    });
    
});